<?php

namespace app\mainadmin\model;
use app\BaseModel;
use think\facade\Cache;
//*------------------------------------------------------ */
//-- 系统设置
/*------------------------------------------------------ */
class LadderModel extends BaseModel
{
	protected $table = 'main_ladder';
//	public  $pk = 'id';
	protected $mkey = 'ladder_row';
   /*------------------------------------------------------ */
    //--  清除memcache
    /*------------------------------------------------------ */
    public function cleanMemcache(){
        Cache::rm($this->mkey);
    }
	/*------------------------------------------------------ */
	//-- 列表
	/*------------------------------------------------------ */
	public function getRows($id){
		$data = Cache::get($this->mkey);

		if (!empty($data)) return $data;
        $data = $this->where(['id'=>$id])->find()->toarray();
		Cache::set($this->mkey,$data,600);
		return $data;

	}
	/*------------------------------------------------------ */
	//-- 保存配置
	/*------------------------------------------------------ */
	public function editSave($setting = array()){
		if (empty($setting) == true || is_array($setting) == false ) return false;
        if($setting['id'] ==1){
            $ids = $setting['id'];
            unset($setting['id']);
            $res = $this->where(['id'=>$ids])->update($setting);
        }else{
            $res = self::create($setting);
        }
		$this->cleanMemcache();
		return $res;
	}



}
